package com.atguigu.controller;

import com.atguigu.pojo.Emp;
import com.atguigu.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: liuaojun
 * @CreateTime: 2025-02-05
 * @Description:
 * @Version: 1.0
 */
@RestController
public class EmpController {
    @Autowired
    EmpService empService;

    @PostMapping("/emp")
    String insertEmp(@RequestBody Emp emp){
        empService.insert(emp);
        return "{'status':'success'}";
    }

    @PutMapping("/emp")
    String updateEmp(@RequestBody Emp emp){
        empService.update(emp);
        return "{'status':'success'}";
    }

    @DeleteMapping("/emp/{eid}")
    String deleteEmp(@PathVariable int eid){
        empService.delete(eid);
        return "{'status':'success'}";
    }

    @GetMapping("/emp/{eid}")
    Emp getEmp(@PathVariable int eid){
        Emp emp = empService.getEmp(eid);
        return emp;
    }

    @GetMapping("/emp")
    List<Emp> getAllEmp(){
        List<Emp> allEmp = empService.getAllEmp();
        return allEmp;
    }
}
